package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import entity.GoodsLabel;
import tools.DBTools;

public class GoodLabelDao {

	
	public void addLabel(GoodsLabel label) {
		 Connection conn = DBTools.getInstance().getConnection();
		String sql = "select sq_good_id.nextval-1 from dual";
		String sql2 = "insert into TBL_GOOD_LABEL values(SQ_LABEL_ID.nextval, sq_good_id.currval, ?)";
		PreparedStatement ps = null;
		PreparedStatement ps2 = null;
		try {
			ps = conn.prepareStatement(sql);
			ps2 = conn.prepareStatement(sql2);
			ps2.setString(1, label.getLabelName());
			ps.executeQuery();
			int executeUpdate = ps2.executeUpdate();
			if(executeUpdate > 0) System.out.println("标签添加成功");
		} catch (SQLException e) {
			System.out.println("标签添加异常");
			e.printStackTrace();
		} finally {
			if(ps!=null) {
				try {
					ps.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			DBTools.getInstance().closeConnection(conn, ps2, null);
		}
	}
}
